﻿<?php
	//la requete fonctionne, mais j'ai toujours pas trouvé comment convertir la date
	@session_start();
	$temps = microtime();
	$temps = explode(' ', $temps);
	$debutscript = $temps[1] + $temps[0]; 
	
	include 'connexionpdo.php';
	if(isset($_POST['connexion']))
	{
		if(isset($_POST['user']) && isset($_POST['mdp']))
		{
			$user = $_POST['user'];
			$mdp = $_POST['mdp'];
			$req = $connexion->query("SELECT password
									  FROM Visiteur
									  WHERE vis_nom = '".$user."'");
									  
			$req->setFetchMode(PDO::FETCH_OBJ); 
				
				
				while($ligne = $req->fetch()) 
				{
					$pass = $ligne->password;
				}
				
			if($pass == $mdp)
			{
				$_SESSION['user'] = $user;
				$_SESSION['mdp'] = $mdp;
				header('Location: Accueil.php');
				exit();
			}
			else
			{
				$erreur = 'Erreur dans la saisie du login/mot de passe';
			}
		}
	} 
	else if(isset($_SESSION['user']) && isset($_SESSION['mdp']))
	{
		header('Location: Accueil.php');
		exit();
	}
?>

	<!DOCTYPE html>  
<html lang="fr">  
	<head>  
		<!-- meta -->
    <meta charset="utf-8" />
    <meta name="keywords" content="mots-clés" />
    <meta name="description" content="description" />
    <meta name="author" content="auteur">

    <!-- include -->
    <link rel="stylesheet" href="./style.css" />	
    

	  <title>GSB</title> 
	</head>
	<body> 
		<header id="hd1">
			
			
			<hgroup>
				<h1>
					<img class="logo-image" alt="logo" src="./images/ICONE.gif" height="100"/>
					Galaxy Swiss Bourdin
				</h1>
				<h2>GESTIONNAIRE DES COMPTES RENDUS</h2>
			</hgroup>

		</header>

	<div id="main">
		<article>
				<center>
				<form action="index.php" method="POST">
					<section>
						<h4><label for="user">Identifiant</label></h4>
						<p><input type="text" name="user" id="user" tabindex="50"required /></p>
					</section>
					<section>
						<h4><label for="mdp">Mot de passe</label></h4>
						<p><input type="password" name="mdp" id="mdp" tabindex="70"required/"></p>
					</section>
					 <!-- A modifier rajouter script de connextion à la base -->
					<button class="connexion" name="connexion" id="connexion" type ="submit">Connexion<br/>
				</form>
				<p>
					<?php if (isset($erreur)) echo $erreur; ?>
				</p>
				</center>
		</article>
		</div>
		
		<?php include('footer.php');?>